<template>
	<view>
		<view class="topbox">
			<view class="title">
				提现金额
				<text class="tips">全部提现（ {{userinfo.money}} ）</text>
			</view>
			<view class="inputbox">
				<image class="qian_icon" src="./static/qianicon.png" mode=""></image>
				<input v-model="form.price" style="font-size: 36rpx;font-weight: bold;" type="number"
					placeholder="请输入提现金额">
			</view>
		</view>
		<view class="line">

		</view>
		<!-- <view class="topbox">
			<view class="title">
				提现账户

			</view>
			<view class="inputbox">
				<input v-model="form.name" style="font-size: 36rpx;font-weight: bold;" type="text"
					placeholder="请输入真实姓名">
			</view>
			<view class="inputbox" v-if="curpay==2">
				<input v-model="form.card" style="font-size: 36rpx;font-weight: bold;" type="number"
					placeholder="请输入银行卡号">
			</view>
			<view class="" v-if="curpay==0||curpay==1">
				<view class="title" style="margin-top: 40rpx;">
					上传收款码
				</view>
				<view class="pic_box">
					<view class="pic_item" v-for="(item,index) in fileList6" :key="index">
						<image class="pic_bg" @click="imgPreview(fileList6,index)" :src="baseurl+item"
							mode="aspectFill">
						</image>
						<view class="pic_item_name" style="background-color: rgba(0, 0, 0, 0.5);" @click="resup(index)">
							重新上传
						</view>
						<view class="delbox" @click="del(index)">
							<image class="del_icon" src="/static/img/picdel.png" mode=""></image>
						</view>
					</view>
					<view class="pic_item" @click="up" v-if="!fileList6.length>0">
						<image class="pic_bg" src="/static/img/upbg.png" mode=""></image>
					</view>
				</view>
			</view>

		</view> -->
		<view class="topbox">
			<view class="title">
				选择提现方式
			</view>
			<view class="inputbox" style="justify-content: space-between;" v-for="(item,index) in paylist" :key="index">
				<view class="flex">
					<image class="wx_icon" :src="'./static/'+item.icon+'.png'" mode=""></image>
					<view style="font-size: 32rpx;margin-left: 20rpx;">
						{{item.name}}
					</view>
				</view>
				<view class="check_box" @click="curpay=index">
					<image class="check_icon" v-if="curpay==index" src="./static/check.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="xline">

		</view>
		<view class="footer">
			<view class="btn" @click="submit">
				确认
			</view>
		</view>

	</view>
</template>

<script>
	import {
		withdraw
	} from '@/api/my.js'
	export default {
		data() {
			return {
				form: {
					price: '',
					name: '',
					card: '',
					image: '',
				},
				userinfo: {},
				paylist: [{
						name: '微信',
						icon: 'wx'
					},
					// {
					// 	name: '支付宝',
					// 	icon: 'alpay'
					// },
					{
						name: '转账',
						icon: 'qian'
					},
				],
				curpay: 0,
				fileList6: [],
				baseurl: ''
			};
		},
		methods: {
			submit() {
				this.form.image = this.fileList6.join(',')

				let {
					price,
					name,
					image,
					card
				} = this.form
				if (!price) {
					this.$u.toast('请输入您要提现的金额')
					return
				}
				// 判断金额大小
				if(price>this.userinfo.money){
					this.$u.toast('您最多提现'+this.userinfo.money)
					return
				}
				if (!name) {
					this.$u.toast('请输入姓名')
					return
				}
				if (this.curpay == 0 || this.curpay == 1) { //需要上传收款码
					if (!image) {
						this.$u.toast('请上传收款码')
						return
					}
				}
				if (this.curpay == 2) { //需要填账号
					if (!card) {
						this.$u.toast('请填写账号')
						return
					}
				}
				withdraw(this.form).then(res=>{
					// console.log(res)
					if(res.data.code==1){
						this.$u.toast(res.data.msg)
						uni.navigateBack()
					}
				})
			},
			imgPreview(urls, i) {
				console.log(urls)
				let us = []
				urls.map(t => {
					us.push(this.baseurl + t)
				})
				uni.previewImage({
					urls: us,
					current: i
				});
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async up(type) {
				let _this = this
				await uni.chooseImage({
					count: 9,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						// console.log(tempFilePaths)
						tempFilePaths.map(t => {
							uni.showLoading({
								title: '上传中'
							})
							uni.uploadFile({
								url: _this.$BASE_URL +
									'/api/common/upload', //仅为示例，非真实的接口地址
								filePath: t,
								name: 'file',
								header: {
									token: uni.getStorageSync('token')
								},
								success: (uploadFileRes) => {
									this.fileList6.push(JSON.parse(uploadFileRes.data)
										.data.url)
									uni.hideLoading()
									uni.showToast({
										title: JSON.parse(uploadFileRes.data)
											.msg,
										icon: 'none'
									})
								},

							});
						})
					}
				});
			},
			del(i) {
				this.fileList6.splice(i, 1)
			},
			async resup(i) {
				let _this = this
				await uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						// console.log(tempFilePaths)
						uni.showLoading({
							title: '上传中'
						})
						uni.uploadFile({
							url: _this.$BASE_URL +
								'/api/common/upload', //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							name: 'file',
							header: {
								token: uni.getStorageSync('token')
							},
							success: (uploadFileRes) => {
								uni.hideLoading()
								_this.$set(_this.fileList6, i, JSON.parse(uploadFileRes.data)
									.data
									.url)
								uni.showToast({
									title: JSON.parse(uploadFileRes.data).msg,
									icon: 'none'
								})
							},
						});
					}
				});
			},
		},
		onLoad() {
			this.userinfo = uni.getStorageSync('userinfo')
			this.baseurl = this.$BASE_URL
		}
	}
</script>

<style lang="less">
	.topbox {
		padding: 38rpx 32rpx 54rpx;
		border-top: 2rpx solid #FAF9F9;

		.title {
			font-size: 30rpx;
			color: #333;
			font-weight: bold;
			display: flex;
			justify-content: space-between;
		}

		.inputbox {
			display: flex;
			align-items: center;
			margin-top: 60rpx;

			.wx_icon {
				width: 83rpx;
				height: 83rpx;
			}

			.qian_icon {
				width: 23rpx;
				height: 30rpx;
				margin-right: 30rpx;
			}

			.check_icon {
				width: 35rpx;
				height: 35rpx;
			}
		}
	}

	.line {
		width: 750rpx;
		height: 19rpx;
		background: #FAF9F9;
	}

	.flex {
		display: flex;
		align-items: center;
	}

	.xline {
		width: 737rpx;
		height: 1rpx;
		background: #F3F4F6;
		margin: auto;
	}

	.btn {

		// padding: 0 310rpx;
		line-height: 114rpx;
		background: linear-gradient(153deg, #FF8717, #FF5F00);
		border-radius: 57rpx;
		color: #fff;
		font-size: 36rpx;
		text-align: center;
	}

	.footer {
		padding: 100rpx 30rpx;
		justify-content: center;
		padding-bottom: 50rpx;
	}

	.tips {
		font-size: 26rpx;
		font-weight: normal;
	}

	.check_box {
		width: 35rpx;
		height: 35rpx;
		border: 2rpx solid #ccc;
		border-radius: 50%;
	}

	.pic_box {
		display: flex;
		flex-wrap: wrap;
		margin-top: 40rpx;

		.pic_item {
			width: 198rpx;
			height: 198rpx;
			position: relative;
			margin-right: 30rpx;
			margin-bottom: 20rpx;
			border-radius: 10rpx;
			overflow: hidden;
		}

		.pic_bg {
			width: 198rpx;
			height: 198rpx;
			position: absolute;
			border-radius: 10rpx;
			top: 0;
			left: 0;
		}

		.pic_item_name {
			text-align: center;
			width: 100%;
			position: absolute;
			bottom: 0;
			color: #fff;
			font-size: 26rpx;
			line-height: 60rpx;
		}
	}

	.delbox {
		width: 29rpx;
		height: 25rpx;
		background: rgba(0, 0, 0, .5);
		border-radius: 7rpx 0 0 12rpx;

		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		top: 0;
		right: 0;
	}

	.del_icon {
		width: 12rpx;
		height: 12rpx;
	}
</style>